<template>
  <div id="receive-manager">
        <div class="receive-items">
            <div class="receive-item" @click="search" :style="{cursor:(!isSearch ? 'wait':'')}">
                <span class="ic-receive ic-search"></span><br/><span class="text">查询</span>
            </div>
            <div class="receive-item" @click="create" v-loading.fullscreen.lock="fullscreenLoading">
                <span class="ic-receive ic-receive-bill"></span><br/><span class="text">生成采购单</span>
            </div>
            <div class="receive-item" @click="manager">
                <span class="ic-receive ic-receive-manager"></span><br/><span class="text">采购单管理</span>
            </div>
            <div class="receive-item" @click="toExport" :style="{cursor:(!isExportShow ? 'not-allowed':'')}" > 
                <span class="ic-receive ic-receive-export" v-loading.fullscreen.lock="fullscreenLoading"></span><br/><span class="text">导出</span>
            </div>

        </div>
          <div class="receive-header">
                
                <div class="receive-content">
                    <table>
                        <tr>
                            <td style="width: 12%">
                                <div class="wrapper">
                                 <span class="text" style="font-weight: bold">收货单查询</span>
                                 </div>
                            </td>
                             <td>
                                <div class="wrapper"><span class="text">单据状态：</span>
                                    <div class="fill">
                                       
                                            <el-select v-model="Status" slot="prepend" placeholder="请选择">
                                                <el-option label="全部" value=""></el-option>
                                                <el-option label="审核" value="sh"></el-option>
                                                <el-option label="结账" value="jz"></el-option>
                                                <el-option label="录入" value="lr"></el-option>
                                                 <el-option label="登账" value="dz"></el-option>
                                            </el-select>
                                           
                                       
                                    </div>
                                </div>
                            </td>
                            <td>
                                <div class="wrapper"><span class="text">发票号：</span>
                                    <div class="fill"><input class="disabled forbid" type="text" v-model="InvoiceNumber"></div>
                                </div>
                            </td>
                            <td>
                                <div class="wrapper"><span class="text">供货商：</span>
                                    <div class="fill"><input class="disabled forbid" type="text" v-model="SupperName" @keyup.enter="supperShow()"></div>
                                </div>
                            </td>
                            <td>
                                <div class="wrapper"><span class="text">起始时间：</span>
                                    <div class="fill">
                                        <div class="block">
                                            <el-date-picker v-model="StartTime" type="datetime" value-format   placeholder="选择起始时间">
                                            </el-date-picker>

   
                                        </div>

                                        <!--  <input type="text" class="disabled forbid" @click="dateStart" v-model="inputTimeStart"> --></div>
                                </div>
                            </td>
                            <td>
                                <div class="wrapper"><span class="text">结束时间：</span>
                                    <div class="fill">
                                        <div class="block">
                                            <el-date-picker v-model="EndTime" type="datetime" format="yyyy-MM-dd HH:mm:ss" placeholder="选择结束时间">
                                            </el-date-picker>
                                        </div>
                                    </div>
                                </div>
                            </td>

                        </tr>

                    </table>
                </div>
            </div>
            <div class="shadow" v-show="isSupperShow" @click='close'></div>
            <div id="supper-wrapper" class="supper-wrapper" v-show="isSupperShow">
                <i class="close el-icon-close" @click="close"></i>
                <el-row>
                    <el-col :span="18"><div class="grid-content bg-purple"><span class="text" style="color: red; font-weight: normal">请双击选择供应商</span><span class="text">拼音码或名称：</span><input type="search" v-model="Supper" @keyup.enter='searchSupper'></div></el-col>
                    <el-col :span="6"><div class="grid-content bg-purple-light"><el-button type="primary" icon="el-icon-search" @click='searchSupper'>搜索</el-button></div></el-col>
                </el-row>
                <div class="supper-content">
                  <el-table
                        :data="Suppliers"
                        v-loading="supperLoading"
                        height='420'
                        border
                        
                        @cell-dblclick="selectedRow"
                        style="width: 100%; ">
                        <el-table-column
                        align="center"
                        prop="SupplierName"
                        label="名称"
                        show-overflow-tooltip
                        width="180">
                        </el-table-column>
                        <el-table-column
                        align="center"
                        show-overflow-tooltip
                        prop="PyCode"
                        label="拼音码"
                        width="180">
                        </el-table-column>
                        <el-table-column
                        prop="Address"
                        align="center"
                        show-overflow-tooltip
                        label="地址"
                        width="180">
                        </el-table-column>
                        <el-table-column
                        align="center"
                        prop="ContactPerson"
                        label="联系人"
                        width="180">
                        </el-table-column>
                        <el-table-column
                        align="center"
                        prop="PhoneNumber1"
                        label="联系电话1"
                        width="180">
                        </el-table-column>
                        align="center"
                        <el-table-column
                        align="center"
                        prop="PhoneNumber2"
                        label="联系电话2"
                        width="180">
                        </el-table-column>
                        <el-table-column
                        prop="PhoneNumber3"
                        align="center"
                        label="联系电话3"
                        width="180">
                        </el-table-column>
                    </el-table>
                </div>
                 <div class="supper-footer">
                    
                    <el-pagination
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    
                    :page-sizes="pageSizes"
                    :page-size="pageSize"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="totalSuppliers">
                    </el-pagination>
                </div>
            </div>
        <div class="table-wrapper">
            <div class="container" id="shTable">
                    
                    <el-table
                        id="out-table"
                        ref="multipleTable"
                        :data="receiveBillData"
                        v-loading="loading"
                        tooltip-effect="dark"
                    :height = 'tableHeight'
                        style="width: 100%;"
                        @expand-change ="handleExpand"
                        @selection-change="handleSelectionChange">
                            <el-table-column type="expand" width="40">
                            <template slot-scope="props">
                                <el-table
                                    :data="props.row.tableData"
                                    border
                                    style="width: 100%">
                                    <el-table-column
                                    prop="GoodsCode"
                                    show-overflow-tooltip
                                    align='left'
                                    label="物品代码"
                                    >
                                    </el-table-column>
                                    <el-table-column
                                    prop="GoodsName"
                                    show-overflow-tooltip
                                    align='left'
                                    label="物品名称"
                                    >
                                    </el-table-column>
                                    <el-table-column
                                    prop="ChargeCodeID"
                                    show-overflow-tooltip
                                    align='left'
                                     
                                    label="收费代码">
                                    </el-table-column>
                                     <el-table-column
                                    prop="medical_code"
                                    show-overflow-tooltip
                                    align='left'
                                    label="医保代码"
                                    >
                                    </el-table-column>
                                    <el-table-column
                                    prop="LatestPrice"
                                    show-overflow-tooltip
                                    align='left'
                                    label="最新单价"
                                    >
                                    </el-table-column>
                                    <el-table-column
                                    prop="GoodsCount"
                                    show-overflow-tooltip

                                    align='left'
                                    label="数量">
                                    </el-table-column>
                                </el-table>
                                
                            </template>
                            </el-table-column>
                            <el-table-column
                                type="selection"
                                align='left'
                                width="50">
                            </el-table-column>
                            <!-- <el-table-column
                            prop="BillTypeStr"
                                label="单据类型"
                                align='left'
                                width="120">
                            
                        
                            </el-table-column> -->
                            <el-table-column prop="BillSN" label="收货单据号"  align='left'  show-overflow-tooltip>
                            </el-table-column>
                            <el-table-column prop="HelpNumber" label="流水号"  align='left'  show-overflow-tooltip>
                            </el-table-column>
                            <el-table-column prop="InputTime" label="录入日期"  align='left'  show-overflow-tooltip>
                            </el-table-column>
                            <el-table-column prop="BookinTime" label="登账日期"   align='left'  show-overflow-tooltip>
                            </el-table-column>
                            <el-table-column prop="SupplierName" label="供货单位"  align='left'  show-overflow-tooltip>
                            </el-table-column>
                            <el-table-column prop="InvoiceNumber" label="发票号"  align='left'  show-overflow-tooltip>
                            </el-table-column>
                            <el-table-column prop="InvoiceDate" label="发票日期"  align='left'  show-overflow-tooltip>
                            </el-table-column>
                            <el-table-column prop="Amount" label="总金额"  align='left'  show-overflow-tooltip>
                            </el-table-column>
                            <el-table-column prop="Status" label="单据状态"  align='left'  show-overflow-tooltip>
                            </el-table-column>
                            <!-- <el-table-column prop="InputUserName" label="录入人"  align='left' width="120" show-overflow-tooltip>
                            </el-table-column>
                            <el-table-column prop="AuditUserName" label="审核人"  align='left' width="120" show-overflow-tooltip>
                            </el-table-column>
                            <el-table-column prop="BookinUserName" label="登账人"  align='left'  width="120" show-overflow-tooltip>
                            </el-table-column> -->
                        

                    </el-table>
                    
                </div>

           
            <div class="shTable-footer">
                <el-pagination
                    @size-change="handleReceiveSizeChange"
                    @current-change="handleReceiveCurrentChange"
                    :page-sizes="receivePageSizes"
                    :page-size="receivePageSize"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="totalReceive">
                </el-pagination>    
                
            </div>  
            <div class="aside">
                    <el-table
                        
                        :data="createReceiveBillData"
                    :height = 'tableHeight'
                        style="width: 100%;">
                            
                            
                            <el-table-column prop="ReceiveBillSN" label="收货单据号"  align='left' width="120" show-overflow-tooltip>
                            </el-table-column>
                        <el-table-column prop="StockBillSN" label="采购单据号"  align='left'  width="120" show-overflow-tooltip>
                            </el-table-column>
                            <el-table-column prop="SupplierName" label="供货单位"  align='left' width="120" show-overflow-tooltip>
                            </el-table-column>
                            <el-table-column prop="InvoiceNumber" label="发票号"  align='left' width="120" show-overflow-tooltip>
                            </el-table-column>
                            <el-table-column prop="Amount" label="金额"  align='left' width="120" show-overflow-tooltip>
                            </el-table-column>
                            
                        

                    </el-table>
            </div>
            <div class="cgTable-footer">
            <span class="text">生成采购单总金额为：{{allAmount.toFixed(2)}}&yen;</span>

            </div>   
    
     </div>      
  </div>


</template>

<script>
    import qs from 'qs'
    import {
        checkTime
    } from 'common/js/utils.js';
     
   import xlsx from 'common/js/xlsx.js';
     
    const IS_DEBUG = true; //如果是测试环境就是true，如果是生产环境就是false

    const commonUrl = IS_DEBUG ? '/wanda' : 'http://192.168.204.30:8089'; //http://192.168.226.55:8081

    export default {
        name: 'receive-manager',
        data() {
            return {
                isSupperShow: false,
                totalSuppliers: null,
                totalReceive: null,
                receivePageSizes: [20, 40, 60],
                receivePageSize: 20,
                receiveNowPage: 1,
                pageSizes: [20, 40, 60],
                pageSize: 20,
                nowPage: 1,
                receiveBillData: [],
                receiveBillHeaderData:[
                    {"BillSN":'收货单据号'}, 
                    {"HelpNumber":'流水号'}, 
                    {"InputTime":'录入日期'},
                    {"BookinTime":'登账日期'},
                    {"SupplierName":'供货单位'},
                    {"InvoiceNumber":'发票号'},
                    {"InvoiceDate":'发票日期'},
                    { "Amount":'总金额'},
                    { "Status": '单据状态'} ],
                receiveBillAllData:[],
                createReceiveBillData: [],
                StartTime: '',
                EndTime: '',
                inputTimeStart: null, //GetPreMonthDay(new Date()) ||
                inputTimeEnd: null, //new Date().format("yyyy-MM-dd hh:mm:ss")
                GoodsBookID: '000000000000LL',
                InvoiceNumber: null,
                Status:null,
                Supper: null,
                SupperName: null,
                SupplierID: null,
                Suppliers: [],
                multipleSelection: [],
                isSearch: true,
                isCreate: true,
                isExport:true,
                isExportShow:false,
                tableHeight: 480,
                tHeight: 300,
                loading: false,
                fullscreenLoading:false,
                supperLoading:false,
                allAmount:0.00,
                  
            }
           
        },
        
        watch: {
            SupperName(curVal, oldVal) {
                if(curVal==""){
                     this.SupplierID =''
                }
            },
            pageSize(curVal, oldVal) {
                if (curVal === oldVal) return;
                var _this = this　;

                this.getSuppliers(_this.nowPage, curVal, _this.Supper)　　　　　　　　
            },
            nowPage(curVal, oldVal) {　　　　　　　　　
                if (curVal === oldVal) return;
                var _this = this;
                this.getSuppliers(curVal, _this.pageSize, _this.Supper)　　　　　　　　
            },

            receivePageSize(curVal, oldVal) {
                if (curVal === oldVal) return;
                var _this = this　;

                this.search(_this.receiveNowPage, curVal)　　　　　　　　
            },
            receiveNowPage(curVal, oldVal) {　　　　　　　　　
                if (curVal === oldVal) return;
                var _this = this;
                this.search(curVal, _this.receivePageSize)　　　　　　　　　　
            },

            StartTime(curVal, oldVal) {
                if (curVal === oldVal) return;
                this.inputTimeStart = new Date(curVal).format("yyyy-MM-dd hh:mm:ss")　
                this.receiveNowPage = 1;
            },
            EndTime(curVal, oldVal) {
                if (curVal === oldVal) return;
                this.inputTimeEnd = new Date(curVal).format("yyyy-MM-dd hh:mm:ss")　;
                this.receiveNowPage = 1;　　　　　　　　
            },
            receiveBillData(curVal, oldVal){
                 if (curVal.length>0){
                     this.isExportShow = true   
                 }else this.isExportShow = false 
            }

        },
        created: function() {
            this.tableHeight = document.body.clientHeight-180; 
        },
        methods: {  //wandaSunStockBill
        
            handleExpand: function(row){
                
                var _this = this 
                if(!row.tableData || row.tableData.length === 0){
                this._fetch(commonUrl+'/wandaSunStockBill/ReceiveBillManager/GetDetailByBillSNForYGPT',{billSN:row.BillSN}).then(function(res){
                   
                    if(res.data.issuccess==0){
                        var tableData= JSON.parse(res.data.result)
                      tableData.forEach(function(item){
                          item.GoodsCount = item.GoodsCount.toFixed(2);
                          item.LatestPrice = item.LatestPrice.toFixed(2);
                      })
                      _this.$set(row, 'tableData', tableData)
                     // row.tableData =tableData
                    }
                })

                }
            },

            selectedRow: function(row) {

                this.SupperName = row.SupplierName;
                this.SupplierID = row.SupplierID;
                this.isSupperShow = false;
            },
            handleSizeChange(val) {
                this.pageSize = val
                    //this.getSuppliers(1, val)
            },
            handleCurrentChange(val) {
                this.nowPage = val

            },
            handleReceiveSizeChange(val) {
                this.receivePageSize = val
                    //this.getSuppliers(1, val)
            },
            handleReceiveCurrentChange(val) {
                this.receiveNowPage = val

            },
            searchSupper: function() {
                var Supper = this.Supper
                this.pageSize = 20
                this.nowPage = 1
                this.getSuppliers(1, 20, Supper)
            },
            supperShow: function() {
                var _this = this;
                this.isSupperShow = true;
                this.Supper = this.SupperName
               console.log(this.$api) 
                this.getSuppliers(_this.nowPage, _this.pageSize,_this.Supper)
            },
            close: function() {
                this.isSupperShow = false;
            },
            toggleSelection: function(rows) {
                if (rows) {
                    rows.forEach(row => {
                        this.$refs.multipleTable.toggleRowSelection(row);
                    });
                } else {
                    this.$refs.multipleTable.clearSelection();
                }
            },
            handleSelectionChange: function(val) {
                
                this.multipleSelection = [];
                var _this = this;
                val.forEach(function(item) {
                        _this.multipleSelection.push(item.BillSN)
                    })
                    //this.multipleSelection = val;
            },
           
           
            export2Excel() {
            
                var _this = this 
                
                let fields = {};
            
                this.receiveBillHeaderData.forEach(item => {
                
                    fields[Object.keys(item)] =item[Object.keys(item)]; //动态生成的头
                });
                let data = JSON.parse(JSON.stringify(this.receiveBillAllData));
                xlsx(data , fields, "收货单列表");
             　 },
            toExport:function(){
                var _this = this;
                if(!this.isExportShow){
                    return;
                }
                
                var  nowPage = 1;
                var  pageSize = 99999
                    
               
                if (!this.isExport) {
                    return false;
                }
                if(!this.checked()){
                    return;    
                }
                var inputTimeStart =  this.checked().inputTimeStart
                var inputTimeEnd = this.checked().inputTimeEnd
                this._getReceiveBillAllData(nowPage, pageSize, inputTimeStart, inputTimeEnd, _this.GoodsBookID, _this.Status,_this.InvoiceNumber, _this.SupplierID);

            },
            checked:function(){
                var _this = this;
                 
                var inputTimeStart, inputTimeEnd;
               
                if (!this.inputTimeStart) {

                    this.$message({
                        message: '请选择开始时间',
                        type: 'warning'
                    });
                    return false;
                }
                if (!this.inputTimeEnd) {

                    this.$message({
                        message: '请选择结束时间',
                        type: 'warning'
                    });
                    return false;
                }
                if (typeof this.inputTimeStart == 'object') {
                    inputTimeStart = this.startTime
                } else inputTimeStart = this.inputTimeStart;
                if (typeof this.inputTimeEnd == 'object') {
                    inputTimeEnd = this.endTime
                } else inputTimeEnd = this.inputTimeEnd;
                if (new Date(inputTimeStart.replace(/-/g, "/")) > new Date(inputTimeEnd.replace(/-/g, "/"))) {

                    this.$message({
                        message: '开始时间不能大于结束时间',
                        type: 'warning'
                    });
                    return false;
                }

                if (!checkTime(inputTimeStart, inputTimeEnd)) {
                    this.$message({
                        message: '日期时间跨度不得超过1个月！',
                        type: 'warning'
                    });
                    return false;
                }
                return{
                    inputTimeStart:inputTimeStart,
                    inputTimeEnd:inputTimeEnd
                }
            },
            search: function(nowPage, pageSize) {
               
                var _this = this;
                 if (!nowPage || !pageSize) {
                    nowPage = 1;
                    pageSize = 20
                    this.receivePageSize = pageSize;
                    this.receiveNowPage = nowPage
                }
                if (!this.isSearch) {
                    return false;
                }
                if(!this.checked()){
                    return;    
                }
                var inputTimeStart =  this.checked().inputTimeStart
                var inputTimeEnd = this.checked().inputTimeEnd
                this._getReceiveBill(nowPage, pageSize, inputTimeStart, inputTimeEnd, _this.GoodsBookID, _this.Status,_this.InvoiceNumber, _this.SupplierID);

            },
            create: function() {
                
                var _this = this;
                if (!this.isCreate) {
                    return;
                }
                if (this.multipleSelection.length === 0) {
                    this.$message({
                        message: '请选择物品',
                        type: 'warning'
                    });
                    return;
                }

                var parms = {
                    billList: JSON.stringify(this.multipleSelection),
                    userID: '00000000000000'
                }
                _this.isCreate = false
                this.fullscreenLoading = true;
                this._fetch(commonUrl+'/wandaSunStockBill/ReceiveYgptManager/GenerateSunStockBill', parms).then(function(res) { //wandaSunStockBill

                    _this.multipleSelection = []
                    _this.fullscreenLoading = false;
                    _this.isCreate = true
                    if(res.data.issuccess==0){
                        var result = JSON.parse(res.data.result)
                        
                     for (var i=0; i < result.length; i++) {  
                         result[i].Amount =result[i].Amount.toFixed(2);
                          _this.createReceiveBillData.push( result[i] );  
                    }  
                     _this.createReceiveBillData.reverse()
                       // _this.createReceiveBillData.concat(result);
                    _this.createReceiveBillData.forEach(function(item){
                         
                       
                            _this.allAmount += Number(item.Amount) 
                    })   
                       
                     _this.search()

                    }else {
                        _this.$alert( '提交失败！！','提示', {
                            type:'error',
                            callback: function() {
                                
                                _this.search()
                            }
                        });
                         
                    }

                }).catch(function(err) {
                    _this.isCreate = true;
                    _this.fullscreenLoading = false;
                })
            },
            manager: function() {
               

               // window.location.href = 'http://192.168.226.55:8081/frm/?password=wonders#/frm/stockBillQuery' //'http://192.168.226.55:8081/frm/?password=wonders#/frm/stockBillQuery' //http://192.168.204.30:8089/frm/?password=wonders#/frm/stockBillQuery
            },
            conditionModel: function(ColumnName, FullString, Oper, Value, Type) {

                var obj = {
                    "ColumnName": ColumnName,
                    "FullString": FullString,
                    "Oper": Oper,
                    "Value": Value,
                    "Type": Type
                }
                return obj;
            },
            conditionsModel: function(Conditions, Type) {
                var obj = {
                    "Conditions": Conditions,
                    "Type": Type
                }
                return obj
            },
            conditionFormat:function(GoodsBookID,inputTimeStart,inputTimeEnd,Status,InvoiceNumber,Supper){
                 var _this = this;
                
                var condition = {}
                var wpid = _this.conditionModel("GoodsBookID", null, "Equal", GoodsBookID, "String")
                var ksid = _this.conditionModel("ProviderDeptAccountID", null, "Equal", "0000000000z-02", "String")

                var kssj = _this.conditionModel("InputTime", null, "MoreOrEqual", inputTimeStart, "DateTime")
                var jssj = _this.conditionModel("InputTime", null, "LessOrEqual", inputTimeEnd, "DateTime")
                var dzzt = _this.conditionModel("Status", null, "Equal", Status, "String")
                var fph = _this.conditionModel("InvoiceNumber", null, "Equal", InvoiceNumber, "String")
                var gys = _this.conditionModel("SupplierID", null, "Equal", Supper, "String")
                var arr = [kssj, jssj, fph, gys,dzzt] 
             
                if (InvoiceNumber == null || _this.isNull(InvoiceNumber)) {
                   
                    arr.remove(fph)
                
                   }
                if (Supper == null || _this.isNull(Supper)) {
                     
                    arr.remove(gys) 
               
                   }
                if (Status == null || _this.isNull(Status)) {
                      
                    arr.remove(dzzt) 
                   
                }
              
                var condition2 = _this.conditionsModel(arr, "AND")

            
                var condition1 = _this.conditionsModel([wpid, ksid], "AND")

                condition = _this.conditionsModel([condition1, condition2], "AND")
                return condition
            },
            isNull:function( str ){ if ( str == "" ) return true; var regu = "^[ ]+$"; var re = new RegExp(regu); return re.test(str); },
            _getReceiveBillAllData: function(nowPage, pageSize, inputTimeStart, inputTimeEnd, GoodsBookID,Status,InvoiceNumber, Supper) {

                var _this = this;
                this.isExport = false;
                var condition = this.conditionFormat(GoodsBookID,inputTimeStart,inputTimeEnd,Status,InvoiceNumber,Supper)

                var parms = {
                    condition: JSON.stringify(condition),
                    nowPage: nowPage,
                    pageSize: pageSize,
                    orderby: ''
                }
                this.fullscreenLoading = true;
                
                this._fetch(commonUrl+'/wandaSunStockBill/ReceiveBillManager/GetAllReceiveBillForYGPT', parms).then(function(result) { //GetAllReceiveBillForYGPT
                    _this.isExport = true;
                   // _this.SupplierID = ''
                    var res = JSON.parse(result.data.result);
                     var result = res.pageContent
                
                    _this.receiveBillAllData = result;
                    for (let i = 0; i < _this.receiveBillData.length; i++) {
                      
                        _this.receiveBillData[i].InputTime = new Date( _this.receiveBillData[i].InputTime).format("yyyy-MM-dd hh:mm:ss")
                         _this.receiveBillData[i].BookinTime = new Date( _this.receiveBillData[i].BookinTime).format("yyyy-MM-dd hh:mm:ss")
                         _this.receiveBillData[i].InvoiceDate = new Date( _this.receiveBillData[i].InvoiceDate).format("yyyy-MM-dd hh:mm:ss")
                       _this.receiveBillData[i].Amount = _this.receiveBillData[i].Amount.toFixed(2)
                      
                        if (_this.receiveBillData[i].Status == 'dz') {
                            _this.receiveBillData[i].Status = '登账'
                        } else if (_this.receiveBillData[i].Status== 'jz') {
                            _this.receiveBillData[i].Status = '结账'
                        } else if (_this.receiveBillData[i].Status== 'lr') {
                            _this.receiveBillData[i].Status = 录入
                        } else if (_this.receiveBillData[i].Status== 'sh') {
                            _this.receiveBillData[i].Status = '审核'
                        } 
                        
                        else _this.receiveBillData[i].Status= ''
                       

                    }
                   
                _this.export2Excel();
                _this.fullscreenLoading = false;
                }).catch(function(err) {
                    _this.isExport = true
                })
            },
           _getReceiveBill: function(nowPage, pageSize, inputTimeStart, inputTimeEnd, GoodsBookID,Status,InvoiceNumber, Supper) {

                var _this = this;
                this.isSearch = false;
                var condition = this.conditionFormat(GoodsBookID,inputTimeStart,inputTimeEnd,Status,InvoiceNumber,Supper)

                var parms = {
                    condition: JSON.stringify(condition),
                    nowPage: nowPage,
                    pageSize: pageSize,
                    orderby: ''
                }
                 this.loading = true;
                this._fetch(commonUrl+'/wandaSunStockBill/ReceiveBillManager/GetAllReceiveBillForYGPT', parms).then(function(result) { //GetAllReceiveBillForYGPT
                    _this.isSearch = true;
                   // _this.SupplierID = ''
                    var res = JSON.parse(result.data.result);
                    var result = res.pageContent;
                
                    _this.receiveBillData = result;
                    for (let i = 0; i < _this.receiveBillData.length; i++) {
                      
                        _this.receiveBillData[i].InputTime = new Date( _this.receiveBillData[i].InputTime).format("yyyy-MM-dd hh:mm:ss")
                         _this.receiveBillData[i].BookinTime = new Date( _this.receiveBillData[i].BookinTime).format("yyyy-MM-dd hh:mm:ss")
                         _this.receiveBillData[i].InvoiceDate = new Date( _this.receiveBillData[i].InvoiceDate).format("yyyy-MM-dd hh:mm:ss")
                       _this.receiveBillData[i].Amount = _this.receiveBillData[i].Amount.toFixed(2)
                      
                        if (_this.receiveBillData[i].Status == 'dz') {
                            _this.receiveBillData[i].Status = '登账'
                        } else if (_this.receiveBillData[i].Status== 'jz') {
                            _this.receiveBillData[i].Status = '结账'
                        } else if (_this.receiveBillData[i].Status== 'lr') {
                            _this.receiveBillData[i].Status = 录入
                        } else if (_this.receiveBillData[i].Status== 'sh') {
                            _this.receiveBillData[i].Status = '审核'
                        } 
                        
                        else _this.receiveBillData[i].Status= ''
                       

                    }
                    _this.totalReceive = res.pageCount;
                    _this.loading = false;
                }).catch(function(err) {
                    _this.isSearch = true
                })
            },

            getSuppliers: function(nowPage, pageSize, vague) {
                var _this = this;
                
                var condition = {}
                var first = _this.conditionModel("1", null, "Equal", 1, "Int32")
                var IsAgent = _this.conditionModel("b.IsAgent", null, "Equal", true, "Boolean")

                if (!vague) {

                    condition = _this.conditionsModel([first, IsAgent], "AND")
                } else {
                    var PyCode = _this.conditionModel("upper(PyCode)", null, "Like", ("%" + vague.toUpperCase() + "%"), "String")
                    var SupplierName = _this.conditionModel("SupplierName", null, "Like", ("%" + vague.toUpperCase() + "%"), "String")
                    var condition1 = _this.conditionsModel([first, IsAgent], "AND")
                    var condition2 = _this.conditionsModel([PyCode, SupplierName], "OR")
                    condition = _this.conditionsModel([condition1, condition2], "AND")

                }
                var parms = {
                    condition: JSON.stringify(condition),
                    nowPage: nowPage,
                    pageSize: pageSize
                }
                this.supperLoading = true;
                this.$api.query(parms).then(function(res){
                    
                   var result = JSON.parse(JSON.parse(res).result)
                    
                    _this.totalSuppliers = result.pageCount
                    _this.Suppliers = result.pageContent
                     _this.supperLoading = false;   
                })
                // this._fetch(commonUrl+'/wandaSunStockBill/SupplierManager/GetSuppliersForWeb', parms).then(function(res) {
                //     var result = JSON.parse(res.data.result)
                //     _this.totalSuppliers = result.pageCount
                //     _this.Suppliers = result.pageContent
                //      _this.supperLoading = false;
                // })
            },
            _fetch: function(url, parms) {

                return this.$http({
                        method: "post",
                        url: url,
                        headers: {
                            'Content-type': 'application/x-www-form-urlencoded'
                        },
                        data: qs.stringify(parms)
                    })
                   
            }
        }
    }
</script>
<style>
  .has-gutter tr th{
        background-color:#eef1f6!important;
        color:#000!important;
        font-weight: bold!important;
    }
</style>
<style scoped>
    #receive-manager {
        position: fixed;
        width: 100%;
        /*min-width: 1100px;*/
        height: 100%;
    }
    
    .receive-items {
        height: 56px;
        font-size: 0;
        border-bottom: 1px solid #ccc;
        padding: 5px 0;
    }
    
    .receive-items .receive-item {
        float: left;
        /* display: inline-block; */
        height: 56px;
        text-align: center;
        vertical-align: middle;
        cursor: pointer;
        margin: 0 10px;
    }
    
    .receive-items .receive-item .ic-receive {
        display: inline-block;
        padding: 16px;
    }
    
    .receive-items .receive-item .text {
        font-size: 14px;
        line-height: 1.5;
    }
    
    .receive-items .receive-item .ic-search {
        background: url("img/ic-search.png") no-repeat;
        background-position: center;
    }
    
    .receive-items .receive-item .ic-receive-bill {
        background: url("img/ic-receive-bill.png") no-repeat;
        background-position: center;
    }
    
    .receive-items .receive-item .ic-receive-manager {
        background: url("img/ic-receive-manager.png") no-repeat;
        background-position: center;
    }
     .receive-items .receive-item .ic-receive-export{
        background: url("img/ic-export.png") no-repeat;
        background-position: center;
     }
    
    .receive-items .receive-item.active .text {
        color: #13227A;
        font-weight: bold;
    }
    
    .receive-header {
        margin: 10px;
    }
    
    .receive-header .receive-title {
        float: left;
        width: 170px;
        margin-top: 5px;
        text-align: center;
    }
    
    .receive-header .receive-title .title {
        font-size: 16px;
        color: #000;
    }
    
    .receive-header .receive-content {
        overflow-x: auto;
        overflow-y: hidden;
    }
    
    .receive-header table {
        width: 100%;
        min-width: 1000px;
    }
    
    .receive-header table td {
        width: 22%;
    }
    
    .receive-header table .wrapper {
        width: 100%;
        height: 40px;
        line-height: 40px;
        font-size: 0;
        position: relative;
        margin: 1px 0;
    }
    
    .receive-header table .text {
        position: absolute;
        top: 0;
        left: 8px;
        font-size: 14px;
        color: darkslategrey;
    }
    
    .receive-header table .value {
        font-size: 14px;
        color: darkslategrey;
    }
    
    .receive-header table .fill {
        margin-left: 80px;
        margin-right: 5px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    
    .receive-header table .block {
        width: 96%;
    }
    
    .receive-header table .block>div {
        width: 100% !important;
    }
    
    .receive-header table input {
        width: 96%;
        height: 38px;
        line-height: 40px;
        font-size: 14px;
        border-radius: 5px;
        border: 1px solid #ddd;
    }
    
    .shadow {
        position: absolute;
        top: 0;
        left: 0;
        z-index: 8;
        width: 100%;
        height: 100%;
        background-color: rgba(0, 0, 0, 0.35)
    }
    
    .close {
        position: absolute;
        font-size: 26px;
        border-radius: 50%;
        border: 1px solid #f1f1f1;
        background-color: #f0f0f0;
        top: -15px;
        right: -15px;
        color: blue;
        cursor: pointer;
        z-index: 100;
    }
    
    .supper-wrapper {
        position: absolute;
        top: 50%;
        left: 50%;
        z-index: 10;
        width: 960px;
        height: 500px;
        transform: translate(-50%, -50%);
        background-color: #f0f0f0;
        border-radius: 10px;
    }
    
    .grid-content {
        height: 36px;
        text-align: left;
        line-height: 36px;
        vertical-align: middle;
    }
    
    .grid-content .el-button {
        padding: 8px 10px !important;
    }
    
    .grid-content .text {
        color: #000;
        font-size: 16px;
        font-weight: bold;
        margin-left: 10px;
    }
    
    .grid-content input {
        height: 30px;
        line-height: 30px;
        width: 300px;
        border: 1px solid #f0f0f0;
        font-size: 14px;
        border-radius: 5px;
    }
    
    .row-bg {
        padding: 10px 0;
    }
    
    .supper-content {
        width: 100%;
        height: 420px;
    }
    
    .supper-footer {
        width: 100%;
        height: 40px;
    }
    .table-wrapper{
        position: absolute;
        top: 130px;
        left: 10px;
        right: 10px;
        bottom: 0;
        overflow: auto;
    }
    .container {
        position: absolute;
        top: 0;
        left: 0;
        right: 300px;
        bottom: 45px;
        overflow: auto;
        border: 1px solid #ddd;
    }
    .aside{
        position: absolute;
        top: 0;
        right:0;
        bottom:45px;
        width: 280px;
        border: 1px solid #ddd; 
        overflow: auto;
    }
    .shTable-footer {
        position: absolute;
        left: 0;
        bottom: 0;
        right: 300px;
        height: 40px;
        overflow: auto;
    }
    .cgTable-footer {
        position: absolute;
        right: 0;
        bottom: 0;
        width: 280px;
        height: 45px;
        line-height: 40px;
        overflow: auto;
    }
    .cgTable-footer .text {
        font-size: 16px;
        color: #2c3e50
    }
    
    .receive-middle {
        border: 1px solid #ccc;
    }
    
    .receive-middle .content {
        width: 100%;
        height: 100%;
        overflow: auto;
    }
    
    .receive-middle .receive-list {
        min-width: 100%;
    }
    
    .receive-middle .receive-list tr {
        cursor: pointer;
    }
    
    .receive-middle .receive-list tr:nth-child(odd) {
        background: #F4F4F4;
    }
    
    .receive-middle .receive-list th,
    .receive-middle .receive-list td {
        height: 24px;
        line-height: 24px;
        text-align: center;
        border: 1px solid #798286;
    }
    
    .receive-middle .receive-list th {
        font-weight: bold;
    }
    
    .receive-middle .receive-list p {
        width: 135px;
        font-size: 12px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    
    .receive-middle .receive-list .active {
        background: #3383b7!important;
    }
  
</style>
